package cn.dong.order.service.impl;

import cn.dong.order.domain.TradePayLog;
import cn.dong.order.mapper.TradePayLogMapper;
import cn.dong.order.service.TradePayLogService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * <p>
 * 支付日志表 服务实现类
 * </p>
 *
 * @author You-Dong
 * @since 2021-02-23
 */
@Service
public class TradePayLogServiceImpl extends ServiceImpl<TradePayLogMapper, TradePayLog> implements TradePayLogService {

    /**
     * 增加日志信息
     *
     * @param returnMap
     */
    @Override
    public void saveOrderLog(Map<String, String> returnMap) {
        TradePayLog tradePayLog = new TradePayLog();
        tradePayLog.setAttr(JSON.toJSONString(returnMap));
        tradePayLog.setOrderNo(returnMap.get("out_trade_no"));
        tradePayLog.setPayTime(new Date());
        tradePayLog.setPayType(1);
        String totalFee = returnMap.get("total_fee");
        tradePayLog.setTotalFee(Long.parseLong(totalFee));
        tradePayLog.setTransactionId(returnMap.get("transaction_id"));
        tradePayLog.setTradeState("1");
        baseMapper.insert(tradePayLog);
    }
}
